package com.ruoyi.system.controller;

import java.util.Date;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.vo.WxMiniRoleVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import com.ruoyi.system.domain.WxMiniRole;
import com.ruoyi.system.service.IWxMiniRoleService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 微信权限Controller
 *
 * @author yy
 * @date 2021-11-05
 */
@Api(tags = " 微信权限")
@RestController
@RequestMapping("/wxMiniRole")
public class WxMiniRoleController extends BaseController {
    @Autowired
    private IWxMiniRoleService wxMiniRoleService;

    /**
     * 查询微信权限列表
     */
    @ApiOperation(value="查询微信权限列表", notes="查询微信权限列表")
    @PreAuthorize(hasPermi = "wxMiniRole:wxMiniRole:list")
    @GetMapping("/list")
    public TableDataInfo list(WxMiniRole wxMiniRole) {
        startPage();
        List<WxMiniRole> list = wxMiniRoleService.selectWxMiniRoleList(wxMiniRole);
        return getDataTable(list);
    }

    /**
     * 导出微信权限列表
     */
    @ApiOperation(value="导出微信权限列表", notes="导出微信权限列表")
    @PreAuthorize(hasPermi = "wxMiniRole:wxMiniRole:export")
    @Log(title = "微信权限", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WxMiniRole wxMiniRole) throws IOException {
        List<WxMiniRole> list = wxMiniRoleService.selectWxMiniRoleList(wxMiniRole);
        ExcelUtil<WxMiniRole> util = new ExcelUtil<WxMiniRole>(WxMiniRole.class);
        util.exportExcel(response, list, "微信权限数据");
    }
    /**
     * 获取微信权限详细信息
     */
    @ApiOperation(value="获取微信权限详细信息", notes="获取微信权限详细信息")
    @PreAuthorize(hasPermi = "wxMiniRole:wxMiniRole:query")
    @GetMapping(value = "/{updateTime}")
    public AjaxResult getInfo(@PathVariable("updateTime") Date updateTime) {
        return AjaxResult.success(wxMiniRoleService.selectWxMiniRoleById(updateTime));
    }

//    /**
//     * 新增微信权限
//     */
//    @ApiOperation(value="新增微信权限", notes="新增微信权限")
//    @PreAuthorize(hasPermi = "wxMiniRole:wxMiniRole:add")
//    @Log(title = "微信权限", businessType = BusinessType.INSERT)
//    @PostMapping
//    public AjaxResult add(@RequestBody WxMiniRole wxMiniRole) {
//        return toAjax(wxMiniRoleService.insertWxMiniRole(wxMiniRole));
//    }

    /**
     * 修改微信权限
     */
    @ApiOperation(value="修改微信权限", notes="修改微信权限")
    @PreAuthorize(hasPermi = "wxMiniRole:wxMiniRole:edit")
    @Log(title = "微信权限", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WxMiniRole wxMiniRole) {
        return toAjax(wxMiniRoleService.updateWxMiniRole(wxMiniRole));
    }

    /**
     * 删除微信权限
     */
    @ApiOperation(value="删除微信权限", notes="删除微信权限")
    @ApiImplicitParam(name = "ids", value = "微信权限ID数组", required = true,paramType = "path", allowMultiple=true, dataType = "String")
    @PreAuthorize(hasPermi = "wxMiniRole:wxMiniRole:remove")
    @Log(title = "微信权限", businessType = BusinessType.DELETE)
    @DeleteMapping("/{updateTimes}")
    public AjaxResult remove(@PathVariable Long[] roleIds) {
        return toAjax(wxMiniRoleService.deleteWxMiniRoleByIds(roleIds));
    }

    /**
     * 删除微信权限
     */
    @ApiOperation(value="保存微信权限", notes="保存微信权限")
    @ApiImplicitParam(name = "roleIds", value = "角色权限IDs", required = true,paramType = "path", allowMultiple=true, dataType = "WxMiniRole")
    @PreAuthorize(hasPermi = "wxMiniRole:wxMiniRole:remove")
    @Log(title = "保存微信权限", businessType = BusinessType.DELETE)
    @PostMapping("/saveWxRoles")
    public AjaxResult saveWxRolesByRoleId(@RequestBody List<WxMiniRole> wxMiniRoles) {
        return toAjax(wxMiniRoleService.saveWxMiniRoleByRolIds(wxMiniRoles));
    }


}
